<?xml version="1.0" encoding="iso-8859-1"?>

<!-- 
  -- Please see the readme.txt file included with this distribution for 
  -- attribution and copyright information.
  -->

<root version="2.0">
	<windowclass name="charsheetmini_basic">
		<placement>
			<size>
				<width>360</width>
				<height>220</height>
			</size>
		</placement>
		<nodelete />
		<sheetdata>
			<!-- HEALTH -->
			<genericcontrol name="mini_hpframe">
				<bounds>0,10,215,145</bounds>
				<frame>
					<name>sheetgroup</name>
				</frame>
			</genericcontrol>

			<hitpointfield name="hp" source="hp.total">
				<anchored>
					<to>mini_hpframe</to>
					<position>insidetopleft</position>
					<offset>15,24</offset>
					<size>
						<width>35</width>
						<height>25</height>
					</size>
				</anchored>
				<noreset />
			</hitpointfield>
			<stringcontrol>
				<anchored>
					<to>hp</to>
					<position>above</position>
					<offset>0,2</offset>
				</anchored>
				<static>HP</static>
				<center />
				<font>sheetlabelsmall</font>
			</stringcontrol>

			<sheetnumber name="hptemp" source="hp.temporary">
				<anchored>
					<to>hp</to>
					<position>right</position>
					<offset>15,0</offset>
					<size>
						<width>35</width>
					</size>
				</anchored>
				<hideonvalue value="0" />
				<frame>
					<name>bonus</name>
					<offset>5,5,5,5</offset>
				</frame>
			</sheetnumber>
			<stringcontrol>
				<anchored>
					<to>hptemp</to>
					<position>above</position>
					<offset>5,2</offset>
				</anchored>
				<static>Temp</static>
				<center />
				<font>sheetlabelsmall</font>
			</stringcontrol>

			<hitpointfield name="wounds" source="hp.wounds">
				<anchored>
					<to>hptemp</to>
					<position>right</position>
					<offset>15,0</offset>
					<size>
						<width>35</width>
					</size>
				</anchored>
				<hideonvalue value="0" />
				<script>
					function onInit()
						if super.onInit then
							super.onInit();
						end

						onValueChanged();
					end
					
					function onDrop(x, y, draginfo)
						if draginfo.getType() == "number" then
							local rActor = CombatCommon.getActor("pc", window.getDatabaseNode());
							RulesManager.applyDamage(rActor, draginfo.getNumberData(), draginfo.getDescription());
						end
						
						return true;
					end
					
					function onValueChanged()
						local percent_wounded = 0;
						if window.hp.getValue() &gt; 0 then
							percent_wounded = window.wounds.getValue() / window.hp.getValue();
						end
						if percent_wounded &lt;= 0 then
							setFont("sheetnumber");
						elseif percent_wounded &lt; .5 then
							setFont("charsheet_light");
						elseif percent_wounded &lt; 1 then
							setFont("charsheet_bloodied");
						else
							setFont("charsheet_dead");
						end
					end
				</script>
			</hitpointfield>
			<stringcontrol>
				<anchored>
					<to>wounds</to>
					<position>above</position>
					<offset>5,2</offset>
				</anchored>
				<static>Wounds</static>
				<center />
				<font>sheetlabelsmall</font>
			</stringcontrol>
			
			<checkcounter name="faileddeathsaves">
				<anchored>
					<to>wounds</to>
					<position>right</position>
					<offset>17,0</offset>
					<size>
						<width>20</width>
					</size>
				</anchored>
				<sourcefields>
					<current>hp.faileddeathsaves</current>
					<maximum>hp.maxdeathsaves</maximum>
				</sourcefields>
				<script>
					function onInit()
						super.onInit();
						setMaxValue(3);
					end
				</script>
			</checkcounter>
			<stringcontrol name="faileddeathlabel">
				<anchored>
					<to>faileddeathsaves</to>
					<position>above</position>
					<offset>5,2</offset>
				</anchored>
				<font>sheetlabelsmall</font>
				<static>FDS</static>
				<center />
			</stringcontrol>

			<sheetnumber name="healsurgesmax" source="hp.surgesmax">
				<anchored>
					<to>mini_hpframe</to>
					<position>insidetopleft</position>
					<offset>15,75</offset>
					<size>
						<width>35</width>
						<height>25</height>
					</size>
				</anchored>
				<hideonvalue value="0" />
				<frame>
					<name>bonus</name>
					<offset>5,5,5,5</offset>
				</frame>
			</sheetnumber>
			<stringcontrol>
				<anchored>
					<to>healsurgesmax</to>
					<position>above</position>
					<offset>5,2</offset>
				</anchored>
				<static>Surges</static>
				<center />
				<font>sheetlabelsmall</font>
			</stringcontrol>

			<sheetnumber name="healsurgesused" source="hp.surgesused">
				<anchored>
					<to>healsurgesmax</to>
					<position>right</position>
					<offset>15,0</offset>
					<size>
						<width>35</width>
					</size>
				</anchored>
				<hideonvalue value="0" />
			</sheetnumber>
			<stringcontrol>
				<anchored>
					<to>healsurgesused</to>
					<position>above</position>
					<offset>5,2</offset>
				</anchored>
				<static>Used</static>
				<center />
				<font>sheetlabelsmall</font>
			</stringcontrol>

			<sheetbonus name="healsurge" source="hp.surge">
				<anchored>
					<to>healsurgesused</to>
					<position>right</position>
					<offset>15,0</offset>
					<size>
						<width>35</width>
					</size>
				</anchored>
				<modifiersize>mini</modifiersize>
				<modifierfield>hp.surgemodifier</modifierfield>
				<source>
					<name>hp.total</name>
					<op>+</op>
				</source>
				<script>
					function onSourceValue(source, sourcename)
						if sourcename == "hp.total" then
							return math.floor(source.getValue() / 4);
						end

						return super.onSourceValue(source, sourcename);
					end
				</script>
			</sheetbonus>			

			<buttoncontrol name="healsurge_button">
				<anchored>
					<to>healsurge</to>
					<position>above</position>
					<size>
						<height>23</height>
					</size>
				</anchored>
				<icon>
					<normal>button_surge</normal>
					<pressed>button_surge_down</pressed>
				</icon>
				<tooltip>
					<text>Apply healing surge</text>
				</tooltip>
				<script>
					function onButtonPress()
						CharSheetCommon.useHealingSurge(window.getDatabaseNode());
					end
				</script>
			</buttoncontrol>

			<savefield name="save" source="defenses.save.total">
				<anchored>
					<to>healsurge</to>
					<position>right</position>
					<offset>15,0</offset>
					<size>
						<width>35</width>
					</size>
				</anchored>
			</savefield>
			<stringcontrol name="savelabel">
				<anchored>
					<to>save</to>
					<position>above</position>
					<offset>5,2</offset>
				</anchored>
				<font>sheetlabelsmall</font>
				<static>Save</static>
				<center />
			</stringcontrol>

			<labeledstring name="specialdefenses" source="defenses.special">
				<anchored>
					<to>mini_hpframe</to>
					<position>insidetopleft</position>
					<offset>15,112</offset>
					<size>
						<width>185</width>
						<height>20</height>
					</size>
				</anchored>
				<label>Immune / Resist / Vulnerable</label>
			</labeledstring>

			<!-- DEFENSES -->
			<genericcontrol name="mini_defenseframe">
				<bounds>0,155,215,65</bounds>
				<frame>
					<name>sheetgroup</name>
				</frame>
			</genericcontrol>

			<defensemain name="ac" source="defenses.ac.total">
				<anchored>
					<to>mini_defenseframe</to>
					<position>insidetopleft</position>
					<offset>15,24</offset>
					<size>
						<width>35</width>
						<height>25</height>
					</size>
				</anchored>
				<modifierfield>defenses.ac.temporary</modifierfield>
				<flag>encumbrance.heavyarmor</flag>
				<bonusfield1>abilities.dexterity.bonus</bonusfield1>
				<bonusfield2>abilities.intelligence.bonus</bonusfield2>
				<selectfield>defenses.ac.abilityname</selectfield>
				<showemptywidget />
				<source>
					<name>levelbonus</name>
					<op>+</op>
				</source>
				<source>
					<name>defenses.ac.armor</name>
					<op>+</op>
				</source>
				<source>
					<name>defenses.ac.misc</name>
					<op>+</op>
				</source>
			</defensemain>
			<stringcontrol>
				<anchored>
					<to>ac</to>
					<position>above</position>
					<offset>0,2</offset>
				</anchored>
				<static>AC</static>
				<center />
				<font>sheetlabelsmall</font>
			</stringcontrol>

			<defensemain name="fortitude" source="defenses.fortitude.total">
				<anchored>
					<to>ac</to>
					<position>right</position>
					<offset>15,0</offset>
					<size>
						<width>35</width>
					</size>
				</anchored>
				<modifierfield>defenses.fortitude.temporary</modifierfield>
				<bonusfield1>abilities.strength.bonus</bonusfield1>
				<bonusfield2>abilities.constitution.bonus</bonusfield2>
				<selectfield>defenses.fortitude.abilityname</selectfield>
				<source>
					<name>levelbonus</name>
					<op>+</op>
				</source>
				<source>
					<name>defenses.fortitude.misc</name>
					<op>+</op>
				</source>
			</defensemain>
			<stringcontrol>
				<anchored>
					<to>fortitude</to>
					<position>above</position>
					<offset>5,2</offset>
				</anchored>
				<static>Fortitude</static>
				<center />
				<font>sheetlabelsmall</font>
			</stringcontrol>

			<defensemain name="reflex" source="defenses.reflex.total">
				<anchored>
					<to>fortitude</to>
					<position>right</position>
					<offset>15,0</offset>
					<size>
						<width>35</width>
					</size>
				</anchored>
				<modifierfield>defenses.reflex.temporary</modifierfield>
				<bonusfield1>abilities.dexterity.bonus</bonusfield1>
				<bonusfield2>abilities.intelligence.bonus</bonusfield2>
				<selectfield>defenses.reflex.abilityname</selectfield>
				<source>
					<name>levelbonus</name>
					<op>+</op>
				</source>
				<source>
					<name>defenses.reflex.armor</name>
					<op>+</op>
				</source>
				<source>
					<name>defenses.reflex.misc</name>
					<op>+</op>
				</source>
			</defensemain>
			<stringcontrol>
				<anchored>
					<to>reflex</to>
					<position>above</position>
					<offset>5,2</offset>
				</anchored>
				<static>Reflex</static>
				<center />
				<font>sheetlabelsmall</font>
			</stringcontrol>

			<defensemain name="will" source="defenses.will.total">
				<anchored>
					<to>reflex</to>
					<position>right</position>
					<offset>15,0</offset>
					<size>
						<width>35</width>
					</size>
				</anchored>
				<modifierfield>defenses.will.temporary</modifierfield>
				<bonusfield1>abilities.wisdom.bonus</bonusfield1>
				<bonusfield2>abilities.charisma.bonus</bonusfield2>
				<selectfield>defenses.will.abilityname</selectfield>
				<source>
					<name>levelbonus</name>
					<op>+</op>
				</source>
				<source>
					<name>defenses.will.misc</name>
					<op>+</op>
				</source>
			</defensemain>
			<stringcontrol>
				<anchored>
					<to>will</to>
					<position>above</position>
					<offset>5,2</offset>
				</anchored>
				<static>Will</static>
				<center />
				<font>sheetlabelsmall</font>
			</stringcontrol>


			<!-- ABILITIES -->
			<genericcontrol name="mini_abilityframe">
				<bounds>215,10,200,210</bounds>
				<frame>
					<name>sheetgroup</name>
				</frame>
			</genericcontrol>

			<abilityscore name="strength" source="abilities.strength.score">
				<anchored>
					<to>mini_abilityframe</to>
					<position>insidetopleft</position>
					<offset>15,24</offset>
				</anchored>
			</abilityscore>
			<abilityscore name="constitution" source="abilities.constitution.score">
				<anchored>
					<to>strength</to>
					<position>belowleft</position>
					<offset>0,10</offset>
				</anchored>
			</abilityscore>
			<abilityscore name="dexterity" source="abilities.dexterity.score">
				<anchored>
					<to>constitution</to>
					<position>belowleft</position>
					<offset>0,10</offset>
				</anchored>
			</abilityscore>
			<abilityscore name="intelligence" source="abilities.intelligence.score">
				<anchored>
					<to>dexterity</to>
					<position>belowleft</position>
					<offset>0,10</offset>
				</anchored>
			</abilityscore>
			<abilityscore name="wisdom" source="abilities.wisdom.score">
				<anchored>
					<to>intelligence</to>
					<position>belowleft</position>
					<offset>0,10</offset>
				</anchored>
			</abilityscore>
			<abilityscore name="charisma" source="abilities.charisma.score">
				<anchored>
					<to>wisdom</to>
					<position>belowleft</position>
					<offset>0,10</offset>
				</anchored>
			</abilityscore>
			
			<abilitycheckbonus name="strengthcheck" source="abilities.strength.check">
				<anchored>
					<to>strength</to>
					<offset>104,0</offset>
				</anchored>
				<target>strength</target>
				<description>
					<text>Strength check</text>
				</description>
				<abilitybonusfield>abilities.strength.bonus</abilitybonusfield>
				<levelbonusfield>levelbonus</levelbonusfield>
			</abilitycheckbonus>
			<abilitycheckbonus name="constitutioncheck" source="abilities.constitution.check">
				<anchored>
					<to>constitution</to>
					<offset>104,0</offset>
				</anchored>
				<target>constitution</target>
				<description>
					<text>Constitution check</text>
				</description>
				<abilitybonusfield>abilities.constitution.bonus</abilitybonusfield>
				<levelbonusfield>levelbonus</levelbonusfield>
			</abilitycheckbonus>
			<abilitycheckbonus name="dexteritycheck" source="abilities.dexterity.check">
				<anchored>
					<to>dexterity</to>
					<offset>104,0</offset>
				</anchored>
				<target>dexterity</target>
				<description>
					<text>Dexterity check</text>
				</description>
				<abilitybonusfield>abilities.dexterity.bonus</abilitybonusfield>
				<levelbonusfield>levelbonus</levelbonusfield>
			</abilitycheckbonus>
			<abilitycheckbonus name="intelligencecheck" source="abilities.intelligence.check">
				<anchored>
					<to>intelligence</to>
					<offset>104,0</offset>
				</anchored>
				<target>intelligence</target>
				<description>
					<text>Intelligence check</text>
				</description>
				<abilitybonusfield>abilities.intelligence.bonus</abilitybonusfield>
				<levelbonusfield>levelbonus</levelbonusfield>
			</abilitycheckbonus>
			<abilitycheckbonus name="wisdomcheck" source="abilities.wisdom.check">
				<anchored>
					<to>wisdom</to>
					<offset>104,0</offset>
				</anchored>
				<target>wisdom</target>
				<description>
					<text>Wisdom check</text>
				</description>
				<abilitybonusfield>abilities.wisdom.bonus</abilitybonusfield>
				<levelbonusfield>levelbonus</levelbonusfield>
			</abilitycheckbonus>
			<abilitycheckbonus name="charismacheck" source="abilities.charisma.check">
				<anchored>
					<to>charisma</to>
					<offset>104,0</offset>
				</anchored>
				<target>charisma</target>
				<description>
					<text>Charisma check</text>
				</description>
				<abilitybonusfield>abilities.charisma.bonus</abilitybonusfield>
				<levelbonusfield>levelbonus</levelbonusfield>
			</abilitycheckbonus>

			<abilitylabel>
				<anchored>
					<to>strengthcheck</to>
				</anchored>
				<static>Strength</static>
			</abilitylabel>
			<abilitylabel>
				<anchored>
					<to>dexteritycheck</to>
				</anchored>
				<static>Dexterity</static>
			</abilitylabel>
			<abilitylabel>
				<anchored>
					<to>constitutioncheck</to>
				</anchored>
				<static>Constitution</static>
			</abilitylabel>
			<abilitylabel>
				<anchored>
					<to>intelligencecheck</to>
				</anchored>
				<static>Intelligence</static>
			</abilitylabel>
			<abilitylabel>
				<anchored>
					<to>wisdomcheck</to>
				</anchored>
				<static>Wisdom</static>
			</abilitylabel>
			<abilitylabel>
				<anchored>
					<to>charismacheck</to>
				</anchored>
				<static>Charisma</static>
			</abilitylabel>
			
			<stringcontrol>
				<anchored>
					<to>strength</to>
					<position>above</position>
					<offset>5,2</offset>
				</anchored>
				<font>sheetlabelsmall</font>
				<static>Score</static>
				<center />
			</stringcontrol>
			<stringcontrol>
				<anchored>
					<to>strengthcheck</to>
					<position>above</position>
					<offset>5,2</offset>
				</anchored>
				<font>sheetlabelsmall</font>
				<static>Check</static>
				<center />
			</stringcontrol>

			<!-- SPEED / ACTION -->
			<genericcontrol name="mini_miscframe">
				<bounds>0,220,125,65</bounds>
				<frame>
					<name>sheetgroup</name>
				</frame>
			</genericcontrol>

			<speedfield name="speedfinal" source="speed.final">
				<anchored>
					<to>mini_miscframe</to>
					<position>insidetopleft</position>
					<offset>20,24</offset>
					<size>
						<width>35</width>
						<height>25</height>
					</size>
				</anchored>
			</speedfield>
			<stringcontrol>
				<anchored>
					<to>speedfinal</to>
					<position>above</position>
					<offset>0,2</offset>
				</anchored>
				<font>sheetlabelsmall</font>
				<static>Speed</static>
				<center />
			</stringcontrol>

			<sheetnumber name="actionpoints">
				<anchored>
					<to>speedfinal</to>
					<position>right</position>
					<offset>15,0</offset>
					<size>
						<width>25</width>
					</size>
				</anchored>
				<noreset />
				<frame>
					<name>bonus</name>
					<offset>5,5,5,5</offset>
				</frame>
				<script>
					function onDoubleClick(x,y)
						CharSheetCommon.useActionPoint(window.getDatabaseNode());
						return true;
					end
				</script>
			</sheetnumber>
			<checkbox name="apused">
				<anchored>
					<to>actionpoints</to>
					<position>right</position>
					<offset>5,0</offset>
					<size>
						<width>15</width>
					</size>
				</anchored>
				<parameters>
					<tooltips>AP Used Since Rest</tooltips>
					<defaulttooltip>AP Not Used Since Rest</defaulttooltip>
				</parameters>
			</checkbox>
			<stringcontrol>
				<anchored>
					<to>actionpoints</to>
					<position>above</position>
					<offset>0,2</offset>
				</anchored>
				<font>sheetlabelsmall</font>
				<static>AP</static>
				<center />
			</stringcontrol>

			<!-- SENSES -->
			<genericcontrol name="mini_sensesframe">
				<bounds>125,220,125,65</bounds>
				<frame>
					<name>sheetgroup</name>
				</frame>
			</genericcontrol>

			<passiveskill name="passiveinsight">
				<anchored>
					<to>mini_sensesframe</to>
					<position>insidetopleft</position>
					<offset>20,24</offset>
					<size>
						<width>35</width>
						<height>25</height>
					</size>
				</anchored>
				<sourcefields>
					<skillname>Insight</skillname>
					<statnodename>wisdom</statnodename>
				</sourcefields>
			</passiveskill>
			<stringcontrol>
				<anchored>
					<to>passiveinsight</to>
					<position>above</position>
					<offset>0,2</offset>
				</anchored>
				<font>sheetlabelsmall</font>
				<static>Insight</static>
			</stringcontrol>

			<passiveskill name="passiveperception">
				<anchored>
					<to>passiveinsight</to>
					<position>right</position>
					<offset>15,0</offset>
					<size>
						<width>35</width>
					</size>
				</anchored>
				<sourcefields>
					<skillname>Perception</skillname>
					<statnodename>wisdom</statnodename>
				</sourcefields>
			</passiveskill>
			<stringcontrol>
				<anchored>
					<to>passiveperception</to>
					<position>above</position>
					<offset>0,2</offset>
				</anchored>
				<font>sheetlabelsmall</font>
				<static>Percept</static>
			</stringcontrol>
			
			<!-- COMBAT ROLLS -->
			<genericcontrol name="mini_combatframe">
				<bounds>250,220,165,65</bounds>
				<frame>
					<name>sheetgroup</name>
				</frame>
			</genericcontrol>

			<init name="initiative" source="initiative.total">
				<anchored>
					<to>mini_combatframe</to>
					<position>insidetopleft</position>
					<offset>15,24</offset>
					<size>
						<width>35</width>
						<height>25</height>
					</size>
				</anchored>
			</init>
			<stringcontrol>
				<anchored>
					<to>initiative</to>
					<position>above</position>
					<offset>0,2</offset>
				</anchored>
				<static>Init</static>
				<center />
				<font>sheetlabelsmall</font>
			</stringcontrol>

			<melee_main name="melee" source="attacks.melee.total">
				<anchored>
					<to>initiative</to>
					<position>right</position>
					<offset>15,0</offset>
					<size>
						<width>35</width>
					</size>
				</anchored>
			</melee_main>
			<stringcontrol>
				<anchored>
					<to>melee</to>
					<position>above</position>
					<offset>0,2</offset>
				</anchored>
				<static>Melee</static>
				<center />
				<font>sheetlabelsmall</font>
			</stringcontrol>

			<ranged_main name="ranged" source="attacks.ranged.total">
				<anchored>
					<to>melee</to>
					<position>right</position>
					<offset>15,0</offset>
					<size>
						<width>35</width>
					</size>
				</anchored>
			</ranged_main>
			<stringcontrol>
				<anchored>
					<to>ranged</to>
					<position>above</position>
					<offset>0,2</offset>
				</anchored>
				<static>Ranged</static>
				<font>sheetlabelsmall</font>
				<center />
			</stringcontrol>

			<!-- WEAPONS -->
			<genericcontrol name="mini_weaponframe">
				<bounds>0,285,-1,-15</bounds>
				<frame>
					<name>sheetgroup</name>
				</frame>
			</genericcontrol>

			<windowlist name="weaponlist">
				<anchored>
					<to>mini_weaponframe</to>
					<position>over</position>
					<offset>-12,-9</offset>
				</anchored>
				<datasource>.weaponlist</datasource>
				<class>charsheetmini_weaponitem</class>
				<script>
					function onSortCompare(w1, w2)
						return w1.order.getValue() &gt; w2.order.getValue();
					end
				</script>
			</windowlist>
			<scrollercontrol>
				<anchored>
					<to>weaponlist</to>
					<position>insidebottomright</position>
					<size>
						<width>45</width>
						<height>27</height>
					</size>
				</anchored>
				<target>weaponlist</target>
				<button>
					<normal>button_scroller</normal>
					<pressed>button_scroller_down</pressed>
				</button>
			</scrollercontrol>
		</sheetdata>
	</windowclass>

	<windowclass name="charsheetmini_weaponitem">
		<sizelimits>
			<minimum>
				<height>10</height>
			</minimum>
		</sizelimits>
		<script>
			function onInit()
				local nodeFocus = getDatabaseNode();

				local nodeAttackMeleeBase = nodeFocus.getChild("...attacks.melee.abilityname");
				if nodeAttackMeleeBase then
					nodeAttackMeleeBase.onUpdate = onAbilityChanged;
				end
				local nodeAttackRangedBase = nodeFocus.getChild("...attacks.ranged.abilityname");
				if nodeAttackRangedBase then
					nodeAttackRangedBase.onUpdate = onAbilityChanged;
				end
				
				for k,v in pairs(DataCommon.abilities) do
					local nodeAbility = nodeFocus.getChild("...abilities." .. v .. ".bonus");
					if nodeAbility then
						nodeAbility.onUpdate = onAbilityChanged;
					end
				end
				
				onAbilityChanged();
			end

			function onAbilityChanged()
				onAttackChanged();
				onDamageChanged();
			end
			
			function highlightAttack(bOnControl)
				if bOnControl then
					attackshade.setFrame("rowshade");
				else
					attackshade.setFrame(nil);
				end
			end
			
			function highlightDamage(bOnControl)
				if bOnControl then
					damageshade.setFrame("rowshade");
				else
					damageshade.setFrame(nil);
				end
			end
			
			function onAttackDrag(draginfo)
				if attackdragging then
					return true;
				end

				local rActor, rAbility, rFocus = CharSheetCommon.getAdvancedRollStructures("attack", nil, getDatabaseNode());
				local attack_name, attack_dice, attack_mod = RulesManager.buildAttackRoll(rActor, rAbility, rFocus);
				dragging = RulesManager.dragAction(draginfo, "attack", attack_mod, attack_name, rActor, attack_dice, true);

				return true;
			end
			
			function onAttackDragEnd(draginfo)
				attackdragging = false;
			end
			
			function onAttackDoubleClick()
				local rActor, rAbility, rFocus = CharSheetCommon.getAdvancedRollStructures("attack", nil, getDatabaseNode());
				local attack_name, attack_dice, attack_mod = RulesManager.buildAttackRoll(rActor, rAbility, rFocus);
				return RulesManager.dclkAction("attack", attack_mod, attack_name, rActor, nil, attack_dice);
			end
			
			function onDamageDrag(draginfo)
				if damagedragging then
					return true;
				end

				local rActor, rAbility, rFocus = CharSheetCommon.getAdvancedRollStructures("damage", nil, getDatabaseNode());
				local damage_name, damage_dice, damage_mod = RulesManager.buildDamageRoll(rActor, rAbility, rFocus);
				dragging = RulesManager.dragAction(draginfo, "damage", damage_mod, damage_name, rActor, damage_dice, true);

				return true;
			end

			function onDamageDragEnd(draginfo)
				damagedragging = false;
			end

			function onDamageDoubleClick()
				local rActor, rAbility, rFocus = CharSheetCommon.getAdvancedRollStructures("damage", nil, getDatabaseNode());
				local damage_name, damage_dice, damage_mod = RulesManager.buildDamageRoll(rActor, rAbility, rFocus);
				return RulesManager.dclkAction("damage", damage_mod, damage_name, rActor, nil, damage_dice);
			end

			function onAttackChanged()
				local nodeFocus = getDatabaseNode();
				local rActor = CombatCommon.getActor("pc", nodeFocus.getChild("..."));

				local mod = bonus.getValue();
				mod = mod + RulesManager.getAbilityBonus(rActor, "halflevel");

				local rFocus = CharSheetCommon.getFocusRecord("attack", nodeFocus);
				if rFocus then
					for k, v in pairs(rFocus.clauses) do
						for k2, v2 in pairs(v.stat) do
							mod = mod + RulesManager.getAbilityBonus(rActor, v2);
						end
					end
				end

				local sValue = "";

				if mod &gt; 0 then
					sValue = "+" .. mod;
				elseif mod &lt; 0 then
					sValue = "" .. mod;
				end

				local sDefense = attackdef.getValue();
				if sDefense ~= "" then
					sValue = sValue .. " vs. ";
					if sDefense == "ac" then
						sValue = sValue .. string.upper(sDefense);
					elseif sDefense == "reflex" then
						sValue = sValue .. string.upper(string.sub(sDefense, 1, 1)) .. string.sub(sDefense, 2, 3);
					else
						sValue = sValue .. string.upper(string.sub(sDefense, 1, 1)) .. string.sub(sDefense, 2, 4);
					end
				end
				
				attackview.setValue(sValue);
			end

			function onDamageChanged()
				local nodeFocus = getDatabaseNode();
				local rActor = CombatCommon.getActor("pc", nodeFocus.getChild("..."));

				local mod = damagebonus.getValue();

				local rFocus = CharSheetCommon.getFocusRecord("damage", nodeFocus);
				if rFocus then
					for k, v in pairs(rFocus.clauses) do
						for k2, v2 in pairs(v.stat) do
							mod = mod + RulesManager.getAbilityBonus(rActor, v2);
						end
					end
				end
				
				local sValue = "";
				if mod &gt; 0 then
					sValue = "+" .. mod;
				elseif mod &lt; 0 then
					sValue = "" .. mod;
				end

				damageview.setValue(sValue);
			end
		</script>
		<sheetdata>
			<numberfield name="order">
				<bounds>0,0,1,1</bounds>
				<invisible />
			</numberfield>
			<checkbox name="type">
				<anchored>
					<left>
						<anchor>right</anchor>
						<offset>-250</offset>
					</left>
					<top>
						<anchor>top</anchor>
					</top>
					<size>
						<width>30</width>
						<height>35</height>
					</size>
				</anchored>
				<parameters>
					<icons>indicator_ranged</icons>
					<defaulticon>indicator_melee</defaulticon>
				</parameters>
				<readonly />
			</checkbox>

			<genericcontrol name="attackshade">
				<anchored>
					<left>
						<parent>type</parent>
						<anchor>right</anchor>
						<offset>3</offset>
					</left>
					<top>
						<anchor>top</anchor>
					</top>
					<size>
						<height>35</height>
						<width>113</width>
					</size>
				</anchored>
			</genericcontrol>
			<genericcontrol name="attackframe">
				<anchored>
					<left>
						<parent>type</parent>
						<anchor>right</anchor>
						<offset>3</offset>
					</left>
					<top>
						<anchor>top</anchor>
					</top>
					<size>
						<height>35</height>
						<width>113</width>
					</size>
				</anchored>
				<frame>
					<name>bonus</name>
				</frame>
				<script>
					function onInit()
						setHoverCursor("hand");
					end
					
					function onHover(bOnControl)
						window.highlightAttack(bOnControl);
					end

					function onDoubleClick(x,y)
						return window.onAttackDoubleClick();
					end			

					function onDrag(button, x, y, draginfo)
						return window.onAttackDrag(draginfo);
					end
					
					function onDragEnd(draginfo)
						return window.onAttackDragEnd(draginfo);
					end
				</script>
			</genericcontrol>
			<genericcontrol name="attackicon">
				<anchored>
					<to>attackframe</to>
					<position>insidetopleft</position>
					<offset>4,0</offset>
					<size>
						<height>35</height>
						<width>30</width>
					</size>
				</anchored>
				<icon>d20icon</icon>
				<script>
					function onInit()
						setHoverCursor("hand");
					end
					
					function onHover(bOnControl)
						window.highlightAttack(bOnControl);
					end

					function onDoubleClick(x,y)
						return window.onAttackDoubleClick();
					end			

					function onDrag(button, x, y, draginfo)
						return window.onAttackDrag(draginfo);
					end
					
					function onDragEnd(draginfo)
						return window.onAttackDragEnd(draginfo);
					end
				</script>
			</genericcontrol>
	
	
			<stringfield name="attackstat">
				<bounds>0,0,1,1</bounds>
				<invisible />
				<script>
					function onValueChanged()
						window.onAttackChanged();
					end
				</script>
			</stringfield>
			<numberfield name="bonus">
				<bounds>0,0,1,1</bounds>
				<invisible />
				<script>
					function onValueChanged()
						window.onAttackChanged();
					end
				</script>
			</numberfield>
			<stringfield name="attackdef">
				<bounds>0,0,1,1</bounds>
				<invisible />
				<script>
					function onValueChanged()
						window.onAttackChanged();
					end
				</script>
			</stringfield>
			<stringcontrol name="attackview">
				<anchored>
					<left>
						<parent>attackicon</parent>
						<anchor>right</anchor>
					</left>
					<top>
						<anchor>top</anchor>
						<offset>10</offset>
					</top>
				</anchored>
				<font>sheettext</font>
				<static />
				<script>
					function onInit()
						setHoverCursor("hand");
					end
					
					function onHover(bOnControl)
						window.highlightAttack(bOnControl);
					end

					function onDoubleClick(x,y)
						return window.onAttackDoubleClick();
					end			

					function onDrag(button, x, y, draginfo)
						return window.onAttackDrag(draginfo);
					end
					
					function onDragEnd(draginfo)
						return window.onAttackDragEnd(draginfo);
					end
				</script>
			</stringcontrol>
			
			<genericcontrol name="damageshade">
				<anchored>
					<left>
						<parent>attackframe</parent>
						<anchor>right</anchor>
					</left>
					<top>
						<anchor>top</anchor>
					</top>
					<size>
						<width>105</width>
						<height>35</height>
					</size>
				</anchored>
			</genericcontrol>
			<genericcontrol name="damageframe">
				<anchored>
					<left>
						<parent>attackframe</parent>
						<anchor>right</anchor>
					</left>
					<top>
						<anchor>top</anchor>
					</top>
					<size>
						<width>105</width>
						<height>35</height>
					</size>
				</anchored>
				<frame>
					<name>slottedbonus</name>
				</frame>
				<script>
					function onInit()
						setHoverCursor("hand");
					end
					
					function onHover(bOnControl)
						window.highlightDamage(bOnControl);
					end

					function onDoubleClick(x,y)
						return window.onDamageDoubleClick();
					end			

					function onDrag(button, x, y, draginfo)
						return window.onDamageDrag(draginfo);
					end
					
					function onDragEnd(draginfo)
						return window.onDamageDragEnd(draginfo);
					end
				</script>
			</genericcontrol>
			<jpgdiefield name="damagedice">
				<anchored>
					<to>damageframe</to>
					<position>insideleft</position>
					<size>
						<width>70</width>
					</size>
				</anchored>
				<shadow>
					<offset>7,1</offset>
					<size>70,20</size>
				</shadow>
				<script>
					function onInit()
						setHoverCursor("hand");
					end
					
					function onHover(bOnControl)
						window.highlightDamage(bOnControl);
					end

					function onDoubleClick(x,y)
						return window.onDamageDoubleClick();
					end			

					function onDrag(button, x, y, draginfo)
						return window.onDamageDrag(draginfo);
					end
					
					function onDragEnd(draginfo)
						return window.onDamageDragEnd(draginfo);
					end
				</script>
			</jpgdiefield>

			<stringfield name="damagestat">
				<bounds>0,0,1,1</bounds>
				<invisible />
				<script>
					function onValueChanged()
						window.onDamageChanged();
					end
				</script>
			</stringfield>
			<numberfield name="damagebonus">
				<bounds>0,0,1,1</bounds>
				<invisible />
				<script>
					function onValueChanged()
						window.onDamageChanged();
					end
				</script>
			</numberfield>
			<stringcontrol name="damageview">
				<anchored>
					<to>damageframe</to>
					<position>insidetopleft</position>
					<offset>71,10</offset>
				</anchored>
				<font>sheettext</font>
				<static />
				<script>
					function onInit()
						setHoverCursor("hand");
					end
					
					function onHover(bOnControl)
						window.highlightDamage(bOnControl);
					end

					function onDoubleClick(x,y)
						return window.onDamageDoubleClick();
					end			

					function onDrag(button, x, y, draginfo)
						return window.onDamageDrag(draginfo);
					end
					
					function onDragEnd(draginfo)
						return window.onDamageDragEnd(draginfo);
					end
				</script>
			</stringcontrol>

			<stringfield name="name">
				<anchored>
					<left>
						<anchor>left</anchor>
						<offset>0</offset>
					</left>
					<top>
						<anchor>top</anchor>
						<offset>6</offset>
					</top>
					<right>
						<parent>type</parent>
						<anchor>left</anchor>
					</right>
				</anchored>
				<font>sheettext</font>
				<frame>
					<name>textline</name>
					<offset>0,0,0,0</offset>
				</frame>
			</stringfield>
			
			<jpgnumberfield name="rangeincrement">
				<anchored>
					<left>
						<anchor>left</anchor>
						<offset>20</offset>
					</left>
					<top>
						<anchor>top</anchor>
						<offset>25</offset>
					</top>
					<size>
						<width>35</width>
						<height>20</height>
					</size>
				</anchored>
				<frame>
					<name>modifier</name>
					<offset>0,3,0,3</offset>
				</frame>
				<font>sheetnumbersmall</font>
				<readonly />
				<script>
					function onInit()
						if super.onInit then
							super.onInit();
						end
						
						onValueChanged();
					end

					function onValueChanged()
						if getValue() &gt; 0 then
							setVisible(true);
							window.range_label.setVisible(true);
						else
							setVisible(false);
							window.range_label.setVisible(false);
						end
					end
				</script>
			</jpgnumberfield>
			<stringcontrol name="range_label">
				<anchored>
					<to>rangeincrement</to>
					<position>lefthigh</position>
					<offset>0,5</offset>
				</anchored>
				<font>sheetlabelsmall</font>
				<static>Rng</static>
			</stringcontrol>
			
			<jpgnumberfield name="maxammo">
				<anchored>
					<to>rangeincrement</to>
					<position>right</position>
					<offset>35,0</offset>
					<size>
						<width>35</width>
					</size>
				</anchored>
				<frame>
					<name>modifier</name>
					<offset>0,3,0,3</offset>
				</frame>
				<readonly />
				<font>sheetnumbersmall</font>
				<script>
					function onInit()
						if super.onInit then
							super.onInit();
						end

						onValueChanged();
					end
					
					function onValueChanged()
						if getValue() &gt; 0 then
							setVisible(true);
							window.ammo_label.setVisible(true);
						else
							setVisible(false);
							window.ammo_label.setVisible(false);
						end
					end
				</script>
			</jpgnumberfield>
			<stringcontrol name="ammo_label">
				<anchored>
					<to>maxammo</to>
					<position>lefthigh</position>
					<offset>0,5</offset>
				</anchored>
				<font>sheetlabelsmall</font>
				<static>Ammo</static>
			</stringcontrol>
		</sheetdata>
	</windowclass>
</root>
